<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module Forwardable - forwardable: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#module-Forwardable-label-Another+example">Another example</a>
    <li><a href="#module-Forwardable-label-Notes">Notes</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-i-def_delegator">#def_delegator</a>
    <li ><a href="#method-i-def_delegators">#def_delegators</a>
    <li ><a href="#method-i-def_instance_delegator">#def_instance_delegator</a>
    <li ><a href="#method-i-def_instance_delegators">#def_instance_delegators</a>
    <li ><a href="#method-i-delegate">#delegate</a>
    <li ><a href="#method-i-instance_delegate">#instance_delegate</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-Forwardable">
    <h1 id="module-Forwardable" class="module">
      module Forwardable
    </h1>

    <section class="description">
    
<p>The <a href="Forwardable.html"><code>Forwardable</code></a> module provides delegation of specified methods to a designated object, using the methods <a href="Forwardable.html#method-i-def_delegator"><code>def_delegator</code></a> and <a href="Forwardable.html#method-i-def_delegators"><code>def_delegators</code></a>.</p>

<p>For example, say you have a class RecordCollection which contains an array <code>@records</code>.  You could provide the lookup method record_number(), which simply calls [] on the <code>@records</code> array, like this:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;forwardable&#39;</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">RecordCollection</span>
  <span class="ruby-identifier">attr_accessor</span> <span class="ruby-value">:records</span>
  <span class="ruby-identifier">extend</span> <span class="ruby-constant">Forwardable</span>
  <span class="ruby-identifier">def_delegator</span> <span class="ruby-value">:@records</span>, <span class="ruby-value">:[]</span>, <span class="ruby-value">:record_number</span>
<span class="ruby-keyword">end</span>
</pre>

<p>We can use the lookup method like so:</p>

<pre class="ruby"><span class="ruby-identifier">r</span> = <span class="ruby-constant">RecordCollection</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">records</span> = [<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>]
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">record_number</span>(<span class="ruby-value">0</span>)  <span class="ruby-comment"># =&gt; 4</span>
</pre>

<p>Further, if you wish to provide the methods size, <<, and map, all of which delegate to @records, this is how you can do it:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">RecordCollection</span> <span class="ruby-comment"># re-open RecordCollection class</span>
  <span class="ruby-identifier">def_delegators</span> <span class="ruby-value">:@records</span>, <span class="ruby-value">:size</span>, <span class="ruby-value">:&lt;&lt;</span>, <span class="ruby-value">:map</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">r</span> = <span class="ruby-constant">RecordCollection</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">records</span> = [<span class="ruby-value">1</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>]
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">record_number</span>(<span class="ruby-value">0</span>)   <span class="ruby-comment"># =&gt; 1</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">size</span>               <span class="ruby-comment"># =&gt; 3</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">4</span>               <span class="ruby-comment"># =&gt; [1, 2, 3, 4]</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> <span class="ruby-value">2</span> }  <span class="ruby-comment"># =&gt; [2, 4, 6, 8]</span>
</pre>

<p>You can even extend regular objects with <a href="Forwardable.html"><code>Forwardable</code></a>.</p>

<pre class="ruby"><span class="ruby-identifier">my_hash</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">my_hash</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">Forwardable</span>              <span class="ruby-comment"># prepare object for delegation</span>
<span class="ruby-identifier">my_hash</span>.<span class="ruby-identifier">def_delegator</span> <span class="ruby-string">&quot;STDOUT&quot;</span>, <span class="ruby-string">&quot;puts&quot;</span>  <span class="ruby-comment"># add delegation for STDOUT.puts()</span>
<span class="ruby-identifier">my_hash</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Howdy!&quot;</span>
</pre>

<h2 id="module-Forwardable-label-Another+example">Another example<span><a href="#module-Forwardable-label-Another+example">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>You could use <a href="Forwardable.html"><code>Forwardable</code></a> as an alternative to inheritance, when you don’t want to inherit all methods from the superclass. For instance, here is how you might add a range of <code>Array</code> instance methods to a new class <code>Queue</code>:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Queue</span>
  <span class="ruby-identifier">extend</span> <span class="ruby-constant">Forwardable</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>
    <span class="ruby-ivar">@q</span> = [ ]    <span class="ruby-comment"># prepare delegate object</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># setup preferred interface, enq() and deq()...</span>
  <span class="ruby-identifier">def_delegator</span> <span class="ruby-value">:@q</span>, <span class="ruby-value">:push</span>, <span class="ruby-value">:enq</span>
  <span class="ruby-identifier">def_delegator</span> <span class="ruby-value">:@q</span>, <span class="ruby-value">:shift</span>, <span class="ruby-value">:deq</span>

  <span class="ruby-comment"># support some general Array methods that fit Queues well</span>
  <span class="ruby-identifier">def_delegators</span> <span class="ruby-value">:@q</span>, <span class="ruby-value">:clear</span>, <span class="ruby-value">:first</span>, <span class="ruby-value">:push</span>, <span class="ruby-value">:shift</span>, <span class="ruby-value">:size</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">q</span> = <span class="ruby-constant">Thread</span><span class="ruby-operator">::</span><span class="ruby-constant">Queue</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">enq</span> <span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>, <span class="ruby-value">4</span>, <span class="ruby-value">5</span>
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">push</span> <span class="ruby-value">6</span>

<span class="ruby-identifier">q</span>.<span class="ruby-identifier">shift</span>    <span class="ruby-comment"># =&gt; 1</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">q</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-identifier">q</span>.<span class="ruby-identifier">deq</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">q</span>.<span class="ruby-identifier">enq</span> <span class="ruby-string">&quot;Ruby&quot;</span>, <span class="ruby-string">&quot;Perl&quot;</span>, <span class="ruby-string">&quot;Python&quot;</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">q</span>.<span class="ruby-identifier">first</span>
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">clear</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">q</span>.<span class="ruby-identifier">first</span>
</pre>

<p>This should output:</p>

<pre class="ruby"><span class="ruby-value">2</span>
<span class="ruby-value">3</span>
<span class="ruby-value">4</span>
<span class="ruby-value">5</span>
<span class="ruby-value">6</span>
<span class="ruby-constant">Ruby</span>
<span class="ruby-keyword">nil</span>
</pre>

<h2 id="module-Forwardable-label-Notes">Notes<span><a href="#module-Forwardable-label-Notes">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Be advised, RDoc will not detect delegated methods.</p>

<p><code>forwardable.rb</code> provides single-method delegation via the <a href="Forwardable.html#method-i-def_delegator"><code>def_delegator</code></a> and <a href="Forwardable.html#method-i-def_delegators"><code>def_delegators</code></a> methods. For full-class delegation via DelegateClass, see <code>delegate.rb</code>.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="FORWARDABLE_VERSION">FORWARDABLE_VERSION
          <dd>
          <dt id="VERSION">VERSION
          <dd><p>Version of <code>forwardable.rb</code></p>
        </dl>
        </section>

        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-c-debug" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">debug</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>ignored</p>
              </div>
            </div>
            </section>


                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-def_delegator" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">def_delegator</span><span
                                class="method-args">(accessor, method, ali = method)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Forwardable.html#method-i-def_instance_delegator">def_instance_delegator</a>
                            </div>
                          </div>

                  <div id="method-i-def_delegators" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">def_delegators</span><span
                                class="method-args">(accessor, *methods)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Forwardable.html#method-i-def_instance_delegators">def_instance_delegators</a>
                            </div>
                          </div>

                  <div id="method-i-def_instance_delegator" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">def_instance_delegator</span><span
                                class="method-args">(accessor, method, ali = method)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Define <code>method</code> as delegator instance method with an optional alias name <code>ali</code>. Method calls to <code>ali</code> will be delegated to <code>accessor.method</code>.  <code>accessor</code> should be a method name, instance variable name, or constant name.  Use the full path to the constant if providing the constant name. Returns the name of the method defined.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">MyQueue</span>
  <span class="ruby-constant">CONST</span> = <span class="ruby-value">1</span>
  <span class="ruby-identifier">extend</span> <span class="ruby-constant">Forwardable</span>
  <span class="ruby-identifier">attr_reader</span> <span class="ruby-value">:queue</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>
    <span class="ruby-ivar">@queue</span> = []
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">def_delegator</span> <span class="ruby-value">:@queue</span>, <span class="ruby-value">:push</span>, <span class="ruby-value">:mypush</span>
  <span class="ruby-identifier">def_delegator</span> <span class="ruby-string">&#39;MyQueue::CONST&#39;</span>, <span class="ruby-value">:to_i</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">q</span> = <span class="ruby-constant">MyQueue</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">mypush</span> <span class="ruby-value">42</span>
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">queue</span>    <span class="ruby-comment">#=&gt; [42]</span>
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">push</span> <span class="ruby-value">23</span>  <span class="ruby-comment">#=&gt; NoMethodError</span>
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">to_i</span>     <span class="ruby-comment">#=&gt; 1</span>
</pre>

                              <div class="method-source-code" id="def_instance_delegator-source">
            <pre><span class="ruby-comment"># File forwardable.rb, line 188</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">def_instance_delegator</span>(<span class="ruby-identifier">accessor</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">ali</span> = <span class="ruby-identifier">method</span>)
  <span class="ruby-identifier">gen</span> = <span class="ruby-constant">Forwardable</span>.<span class="ruby-identifier">_delegator_method</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">accessor</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">ali</span>)

  <span class="ruby-comment"># If it&#39;s not a class or module, it&#39;s an instance</span>
  <span class="ruby-identifier">mod</span> = <span class="ruby-constant">Module</span> <span class="ruby-operator">===</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">singleton_class</span>
  <span class="ruby-identifier">ret</span> = <span class="ruby-identifier">mod</span>.<span class="ruby-identifier">module_eval</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">gen</span>)
  <span class="ruby-identifier">mod</span>.<span class="ruby-identifier">__send__</span>(<span class="ruby-value">:ruby2_keywords</span>, <span class="ruby-identifier">ali</span>) <span class="ruby-keyword">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-string">&#39;2.7&#39;</span>
  <span class="ruby-identifier">ret</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Forwardable.html#method-i-def_delegator">def_delegator</a>
                            </div>

                          </div>

                  <div id="method-i-def_instance_delegators" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">def_instance_delegators</span><span
                                class="method-args">(accessor, *methods)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Shortcut for defining multiple delegator methods, but with no provision for using a different name.  The following two code samples have the same effect:</p>

<pre class="ruby"><span class="ruby-identifier">def_delegators</span> <span class="ruby-value">:@records</span>, <span class="ruby-value">:size</span>, <span class="ruby-value">:&lt;&lt;</span>, <span class="ruby-value">:map</span>

<span class="ruby-identifier">def_delegator</span> <span class="ruby-value">:@records</span>, <span class="ruby-value">:size</span>
<span class="ruby-identifier">def_delegator</span> <span class="ruby-value">:@records</span>, <span class="ruby-value">:&lt;&lt;</span>
<span class="ruby-identifier">def_delegator</span> <span class="ruby-value">:@records</span>, <span class="ruby-value">:map</span>
</pre>

                              <div class="method-source-code" id="def_instance_delegators-source">
            <pre><span class="ruby-comment"># File forwardable.rb, line 156</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">def_instance_delegators</span>(<span class="ruby-identifier">accessor</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">methods</span>)
  <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">method</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-regexp">/\A__(?:send|id)__\z/</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">method</span>
    <span class="ruby-identifier">def_instance_delegator</span>(<span class="ruby-identifier">accessor</span>, <span class="ruby-identifier">method</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Forwardable.html#method-i-def_delegators">def_delegators</a>
                            </div>

                          </div>

                  <div id="method-i-delegate" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          delegate method &rarr; accessor
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          delegate [method, method, ...] &rarr; accessor
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Forwardable.html#method-i-instance_delegate">instance_delegate</a>
                            </div>
                          </div>

                  <div id="method-i-instance_delegate" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">instance_delegate</span><span
                                class="method-args"> [method, method, ...] =&gt; accessor</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Takes a hash as its argument.  The key is a symbol or an array of symbols.  These symbols correspond to method names, instance variable names, or constant names (see <a href="Forwardable.html#method-i-def_delegator"><code>def_delegator</code></a>).  The value is the accessor to which the methods will be delegated.</p>

                              <div class="method-source-code" id="instance_delegate-source">
            <pre><span class="ruby-comment"># File forwardable.rb, line 135</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">instance_delegate</span>(<span class="ruby-identifier">hash</span>)
  <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">methods</span>, <span class="ruby-identifier">accessor</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">each</span>)
      <span class="ruby-identifier">def_instance_delegator</span>(<span class="ruby-identifier">accessor</span>, <span class="ruby-identifier">methods</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">method</span><span class="ruby-operator">|</span> <span class="ruby-identifier">def_instance_delegator</span>(<span class="ruby-identifier">accessor</span>, <span class="ruby-identifier">method</span>)}
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Forwardable.html#method-i-delegate">delegate</a>
                            </div>

                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

